<?php
	require_once('../conexion/conexion.php');
	require_once("../Funciones/funciones_publicas.php");
	$fun = new funciones_publicas();
	//echo $_GET['items'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
<style>
label.texto
{
    font-family:Arial;
	font-style:normal;
	font-size:10pt;
	color:#000000;
}
.caja
{
	font-family:Arial;
	font-style:normal;
	font-size:10pt;
	color:#000000;
	text-decoration: none;
	background-color: #FFFFFF;
	border: 0px;
	border-left: 0px solid #6C6C6C;
	border-right: 0px solid #6C6C6C;
	text-align:right;
}
.area
{
	font-family:Arial;
	font-style:normal;
	font-size:9pt;
	color:#000000;
	border-style:solid; 
	border-top-width:0px; 
	border-right-width:0px; 
	border-bottom-width:0px;
	border-left-width:0px;
	overflow:hidden;
}
.texto
{
	font-family:Arial;
	font-style:normal;
	font-size:10pt;
	color:#000000;
	text-align:center;
}
.datos
{
	font-family:Arial;
	font-style:normal;
	font-size:9pt;
	color:#000000;
	text-align:center;
}
.resp
{
	font-family:Arial;
	font-style:normal;
	font-size:10pt;
	color:#000000;
}
.digito
{
	font-family:Arial;
	font-style:normal;
	font-size:10pt;
	color:#000000;
}
</style>
<script>
function imprSelec()
{
  //document.getElementById('btn_Imprimir').style.display = 'none';
  //var ficha = document.getElementById('seleccion');
  //var ventimp = window.open(' ', 'popimpr');
  //ventimp.document.write( ficha.innerHTML );
  //ventimp.document.close();
  //ventimp.print( );
  //ventimp.close();
  window.print();
  window.close();
  //document.getElementById('btn_Imprimir').style.display = 'block';
} 

function window.onbeforeprint()
{ 
	document.getElementById('btn_Imprimir').style.display = 'none';
} 
function window.onafterprint()
{ 
	document.getElementById('btn_Imprimir').style.display = 'block';
}
function Imprimir()
{
	window.print();
}

function AbreVentana()
{
	var ficha = document.getElementById('seleccion');
  	var ventimp = window.open(' ', 'popimpr');
  	ventimp.document.write( ficha.innerHTML );
}
</script>
</head>

<body>
<form name="facexen" id="facexen" method="post">
<?php
	extract($_POST);
	
	//datos del cliente
	$fechaFac = explode("-",$_GET['fechaNota']);
	$dia = $fechaFac[0];
	$mes = $fechaFac[1];
	$agno = substr($fechaFac[2], -2);
	$palMes = $fun->SeleccionaMes($mes);
	
	/*$con = new Conexion();
    $con2 = $con->conexionBD("fpproduccion");
    $sql = "select 
				OCliRSocial,
				OCliDireccion,
				OCliGiro,
				OCliComuna
				
				from otrosclientes 
				where OCliRut='".$_GET['rut']."'";
    $res = mysql_query($sql) or die ($con->error_mysql("Error en la consulta".mysql_error()));
	$cliente = mysql_fetch_array($res);
	$con->cerrarBD();*/
	
	//buscamos la condicion de venta de la factura
	$con = new Conexion();
    $con2 = $con->conexionBD("fpproduccion");
	if($_GET['doc']=='PSMB')
	{
    	$sql = "select ConVentaDescrip from CondicionVenta cv inner join Factura f on cv.ConVentaCod=f.ConVentaCod where FacCod='".$_GET['fac']."'";
		$sql2 = "select CliRSocial,CliDireccion,CliGiro,CliComuna from clientes where CliRut='".$_GET['rut']."'";
	}
	else
	{
		if($_GET['doc']=='DIA')
		{
			$sql = "select ConVentaDescrip from CondicionVenta cv inner join facturadia f on cv.ConVentaCod=f.ConVentaCod where FacDiaNumFac='".$_GET['fac']."'";
			$sql2 = "select CliRSocial,CliDireccion,CliGiro,CliComuna from clientes where CliRut='".$_GET['rut']."'";
		}
		else
		{
			if($_GET['doc']=='INFA')
			{
				$sql = "select ConVentaDescrip from CondicionVenta cv inner join facturainfa f on cv.ConVentaCod=f.ConVentaCod where FacInfaNumFac='".$_GET['fac']."'";
				$sql2 = "select CliRSocial,CliDireccion,CliGiro,CliComuna from clientes where CliRut='".$_GET['rut']."'";
			}
			else
			{
				if($_GET['doc']=='OTROS')
				{
					$sql = "select ConVentaDescrip from CondicionVenta cv inner join facturaotros f on cv.ConVentaCod=f.ConVentaCod where FacOtrosNumFac='".$_GET['fac']."'";
					$sql2 = "select OCliRSocial,OCliDireccion,OCliGiro,OCliComuna from otrosclientes where OCliRut='".$_GET['rut']."'";
				}
			}
		}
	}
    $res = mysql_query($sql) or die ($con->error_mysql("Error en la consulta".mysql_error()));
	$res2 = mysql_query($sql2) or die ($con->error_mysql("Error en la consulta".mysql_error()));
	$cliente = mysql_fetch_array($res2);
	
	$nombre = utf8_decode($cliente[0]);
	$dir = utf8_decode($cliente[1]);
	$giro = utf8_decode($cliente[2]);
	$comuna = utf8_decode($cliente[3]);
	
	$venta = mysql_fetch_array($res);
	$con->cerrarBD();
?>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
  <td align="center"><input name="btn_Imprimir" id="btn_Imprimir" type="button" onclick="Imprimir();" value="Imprimir" /></td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
	<td colspan="2" style="height:135px;">&nbsp;</td>
</tr>
<tr>
	<td width="84%">&nbsp;</td>
	<td width="16%">&nbsp;</td>
</tr>
<tr>
	<td width="84%"><div style="padding-left:76px"><label class="texto"><?php echo $dia;?></label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label class="texto"><?php echo $palMes;?></label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label class="texto"><?php echo $agno;?></label></div></td>
	<td width="16%">&nbsp;</td>
</tr>
<tr>
	<td><div style="padding-left:92px; padding-top:10px;"><label class="datos"><?php echo $nombre;?></label></div></td>
	<td><div style="padding-left:0px;padding-top:10px;"><label class="digito"><?php echo $_GET['rut'];?></label></div></td>
</tr>
<tr>
	<td><div style="padding-left:85px;padding-top:10px;"><label class="datos"><?php echo $dir;?></label></div></td>
	<td><div style="padding-left:0px;padding-top:10px;"><label class="datos"><?php echo $comuna;?></label></div></td>
</tr>
<tr>
	<td><div style="padding-left:60px;padding-top:10px;"><label class="datos"><?php echo $giro;?></label></div></td>
	<td><div style="padding-left:0px;padding-top:10px;"><label class="datos"><?php echo $comuna;?></label></div></td>
</tr>
<tr>
	<td><div style="padding-left:150px;padding-top:10px;"><label class="digito"><?php echo $_GET['fac'];?></label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label class="digito"><?php echo $_GET['fechaFac'];?></label></div></td>
	<td><div style="padding-left:45px;padding-top:10px;"><label class="datos"><?php echo $venta[0];?></label></div></td>
</tr>
</table>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
	<td colspan="4" style="height:35px;">&nbsp;</td>
</tr>
<tr>
	<td width="18%">&nbsp;</td>
	<td width="50%">&nbsp;</td>
	<td width="15%">&nbsp;</td>
	<td width="17%">&nbsp;</td>
</tr>
<?php
	$suma = 0;
	$cont = 0;
	//echo $_GET['items'];
	$vector = explode(";",$_GET['items']);
	$cant = (count($vector)-1)/4;
	//echo $cant;
	
	for($i=1;$i<=$cant;$i++)
	{
			echo "<tr>";
			echo "<td width='18%' style='text-align:left;padding-left:50px;vertical-align:top;'><label class='digito'>".$vector[$cont]."</label></td>";
			echo "<td width='50%' class='resp'><div style='width:350px;'>".$vector[$cont+1]."</div></td>";
			echo "<td width='15%' style='text-align:right;padding-right:20px;vertical-align:top;'><label class='digito'>".number_format($vector[$cont+2],0,',','.')."</label></td>";
			echo "<td width='17%' style='text-align:right;vertical-align:top;'><label class='digito'>".number_format($vector[$cont+3],0,',','.')."</label></td>";
			echo "</tr>";
			$suma += $vector[$cont+3];
			$cont += 4;
	}
	$iva = round($suma*0.19);
	$total = $iva+$suma;
	$pal=$fun->numletras($total);
?>
</table>
<div style="position:absolute; top:492px; left:65px"><textarea name="txtPalabras" cols="70" rows="3" class="area"><?php echo $pal;?></textarea></div>
<div style="position:absolute; top:500px; left:580px;"><input name="txtTotal" type="text"  class="caja" readonly="true" size="12" value="<?php echo number_format ($suma,0,',','.')?>" /></div>
<div style="position:absolute; top:530px; left:580px;"><input name="txtTotal" type="text"  class="caja" readonly="true" size="12" value="<?php echo number_format ($iva,0,',','.')?>" /></div>
<div style="position:absolute; top:560px; left:580px;"><input name="txtTotal" type="text"  class="caja" readonly="true" size="12" value="<?php echo number_format ($total,0,',','.')?>" /></div>
</form>
</body>
</html>